import { defineConfig, type DefaultTheme } from 'vitepress'
import menu from './menu'

const getSidebar = () => {
  const res: DefaultTheme.SidebarMulti = {}
  Object.keys(menu).forEach(item => {
    const key = menu[item].sidebar.base;
    res[key] = menu[item].sidebar;
  })
  return res;
}

function getNav(): DefaultTheme.NavItem[] {
  const getItems = (keys: string[]) => keys.map(item => {
    return menu[item].nav;
  })
  return [
    {
      text: '介绍',
      activeMatch: '/guide/',
      link: '/guide/front',
    },
    {
      text: 'web开发',
      activeMatch: '/front/',
      items: [
        {
          items: getItems(['html', 'css', 'javaScript', 'nodejs', 'typeScript', 'vue']),
        },
        // {
        //   items: getItems([]),
        // },
        ...getItems(['framework', 'standard', 'build', 'dependence', 'special']),
      ]
    },
    {
      text: 'java开发',
      activeMatch: '/back/',
      link: '/back/java/java',
      // items: [
      //   { text: '语言', items: getItems(['html', 'javaScript', 'typeScript', 'vue']) },
      //   { text: '框架', items: [] }
      // ]
    },
    {
      text: 'DevOps',
      activeMatch: '/devops/',
      link: '/devops/docker',
    },
    {
      text: '平台',
      activeMatch: '/platform/',
      link: '/platform/linux',
    },
    {
      text: '工具',
      activeMatch: '/tools/',
      link: '/tools/develop/vscode',
    },
  ]
}

export const zh = defineConfig({
  lang: 'zh-Hans',
  description: '由 Vite 和 Vue 驱动的静态站点生成器',

  themeConfig: {
    nav: getNav(),

    sidebar: getSidebar(),

    docFooter: {
      prev: '上一页',
      next: '下一页'
    },

    outline: {
      label: '页面导航',
      level: [2, 3]
    },

    lastUpdated: {
      text: '最后更新于',
      formatOptions: {
        dateStyle: 'short',
        timeStyle: 'medium'
      }
    },

    langMenuLabel: '多语言',
    returnToTopLabel: '回到顶部',
    sidebarMenuLabel: '菜单',
    darkModeSwitchLabel: '主题',
  }
})


export const search: DefaultTheme.AlgoliaSearchOptions['locales'] = {
  zh: {
    placeholder: '搜索文档',
    translations: {
      button: {
        buttonText: '搜索文档',
        buttonAriaLabel: '搜索文档'
      },
      modal: {
        searchBox: {
          resetButtonTitle: '清除查询条件',
          resetButtonAriaLabel: '清除查询条件',
          cancelButtonText: '取消',
          cancelButtonAriaLabel: '取消'
        },
        startScreen: {
          recentSearchesTitle: '搜索历史',
          noRecentSearchesText: '没有搜索历史',
          saveRecentSearchButtonTitle: '保存至搜索历史',
          removeRecentSearchButtonTitle: '从搜索历史中移除',
          favoriteSearchesTitle: '收藏',
          removeFavoriteSearchButtonTitle: '从收藏中移除'
        },
        errorScreen: {
          titleText: '无法获取结果',
          helpText: '你可能需要检查你的网络连接'
        },
        footer: {
          selectText: '选择',
          navigateText: '切换',
          closeText: '关闭',
          searchByText: '搜索提供者'
        },
        noResultsScreen: {
          noResultsText: '无法找到相关结果',
          suggestedQueryText: '你可以尝试查询',
          reportMissingResultsText: '你认为该查询应该有结果？',
          reportMissingResultsLinkText: '点击反馈'
        }
      }
    }
  }
}
